package com.guadoutech.lehuoer;

import android.os.Bundle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.guadoutech.lehuoer.utils.CheckFaceUtils;

//import androidx.core.splashscreen.SplashScreen;

import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodChannel;

public class MainActivity extends FlutterActivity {

//    private SplashScreen mSplashScreen;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
//        mSplashScreen = SplashScreen.installSplashScreen(this);
//        mSplashScreen.setKeepOnScreenCondition(() -> true);

        super.onCreate(savedInstanceState);
    }

    @Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
        super.configureFlutterEngine(flutterEngine);

        MethodChannel methodChannel = new MethodChannel(flutterEngine.getDartExecutor(), "com.room/opapp");

        methodChannel.setMethodCallHandler((call, result) -> {
            //检查人脸数量
            if (call.method.equals("checkFace")) {
                String imagePath = (String) call.arguments;
                int faceCount = CheckFaceUtils.checkFace(imagePath);
                result.success(faceCount);

            } else if (call.method.equals("bringAppToForeground")) {
                //启动MainActivity自己
                Log.d("MainActivity", "执行 methodChannel -> bringAppToForeground");

//                Intent intent = new Intent(this, MainActivity.class);
//                intent.setAction(Intent.ACTION_MAIN);
//                intent.addCategory(Intent.CATEGORY_LAUNCHER);
//                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
//                startActivity(intent);

//                ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
//                List<ActivityManager.AppTask> appTasks = activityManager.getAppTasks();
//                if (!appTasks.isEmpty()) {
//                    appTasks.get(0).moveToFront();
//                }

//                PackageManager packageManager = getPackageManager();
//                Intent intent = packageManager.getLaunchIntentForPackage("com.hongyegroup.zhurijob");
//                if (intent != null) {
//                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                    startActivity(intent);
//                }

            } else if (call.method.equals("getNativeRouterName")) {
                // 获取当前需要跳转的子路由
                Log.d("MainActivity", "执行 methodChannel -> getNativeRouterName");
//                result.success(RouterActivity.ROUTER_NAME);
                result.success("");

            } else if (call.method.equals("clearNativeRouterName")) {
                // 清除当前需要跳转的子路由
                Log.d("MainActivity", "执行 methodChannel -> clearNativeRouterName");
//                RouterActivity.ROUTER_NAME = "";
                result.success(true);
            } else if (call.method.equals("appleLogin")) {
                // 苹果登录-Android空实现
                result.success(null);
            } else if (call.method.equals("skipAndroidSplashScreen")) {
                // 跳过Android的SplashScreen
                Log.d("MainActivity", "执行 methodChannel -> skipAndroidSplashScreen");
//                if (mSplashScreen != null) {
//                    mSplashScreen.setKeepOnScreenCondition(() -> false);
//                }
                result.success(true);
            } else {
                result.notImplemented();
            }
        });

    }

}
